package model.admin;

import java.sql.ResultSet;
import java.util.ArrayList;

import myutil.Connect;

import vo.BatchDetailsVo;

public class ModifyBatchDetailsMo {

	public Boolean editBatchDetails(ArrayList<BatchDetailsVo> BatchDetails) {
		String query = "";
		return true;
	}

	public int addBatchDetails(BatchDetailsVo newBatch, String degree_name) {

		String query = "INSERT INTO batch_details " + "(batch_name,"
				+ " start_date, " + "end_date, " + "student_count, "
				+ "start_year, " + "incharge_id, " + "description,status)"
				+ " VALUES ('" + newBatch.getBatch_name() + "'," + " '"
				+ newBatch.getStart_date() + "', " + "'"
				+ newBatch.getEnd_date() + "'," + ""
				+ newBatch.getStudent_count() + "," + ""
				+ newBatch.getStart_year() + ", " + ""
				+ newBatch.getIncharge_id() + "," + " '"
				+ newBatch.getDescription() + "',1);";
		int result;
		String query1= "select max(batch_id) as batch_id from batch_details;";
		int batch_id=0;
		Connect c = new Connect();
		try {
			c.dml(query);
			ResultSet r= c.getResult(query1);
			if(r.next())
				batch_id=r.getInt("batch_id");
			query1="INSERT INTO degree_management (degree_id,degree_incharge_id, batch_id, incharge_start_date, incharge_end_date, description) VALUES " +
					"((select degree_id from degree_details where degree_name='"+degree_name+"')," +
					"(select staff_id from college_staff where staff_name='"+
					newBatch.getIncharge_name()+"')," +
					batch_id+",'" +
					newBatch.getIncharge_start_date()+"' ,'" +
					newBatch.getIncharge_end_date()+"', '" +
					newBatch.getDescription()+"');";
			System.out.println(query1);
			c.dml(query1);
			
			result = 1;

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			result = -1;
		}
		return result;
	}

	public int editBatchDetails(BatchDetailsVo newBatch) {

		String query = "UPDATE batch_details set batch_name='"
				+ newBatch.getBatch_name() + "'," + "start_date='"
				+ newBatch.getStart_date() + "', " + "end_date='"
				+ newBatch.getEnd_date() + "'," + "student_count="
				+ newBatch.getStudent_count() + "," + "start_year="
				+ newBatch.getStart_year() + ", " + "incharge_id="
				+ newBatch.getIncharge_id() + "," + "description= '"
				+ newBatch.getDescription() + "' where batch_id="+newBatch.getBatch_id()+";";
		int result ;
		Connect c = new Connect();
		System.out.println("\n Query is "+query);
		try {
			c.dml(query);
			result = 1;

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			result = -1;
		}
		return result;
	}

	public int deleteBatchDetails(int batch_id) {
		String query="update batch_details set status=0 where batch_id="+batch_id+";";
		
		int result;
		Connect c = new Connect();
		try {
			c.dml(query);
			result = 1;

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			result = -1;
		}
		return result;
	}

}
